﻿namespace DomainServices.Tools
{
    using System;
    using System.ComponentModel.DataAnnotations;

    internal class DisplayCustomAttributeBuilder : StandardCustomAttributeBuilder
    {
        public override AttributeDeclaration GetAttributeDeclaration(Attribute attribute)
        {
            DisplayAttribute attribute2 = (DisplayAttribute) attribute;
            AttributeDeclaration declaration = new AttributeDeclaration(typeof(DisplayAttribute));
            Type attributeType = attribute.GetType();
            try
            {
                attribute2.GetName();
            }
            catch (InvalidOperationException exception)
            {
                throw new AttributeBuilderException(exception, attributeType, "Name");
            }
            try
            {
                attribute2.GetShortName();
            }
            catch (InvalidOperationException exception2)
            {
                throw new AttributeBuilderException(exception2, attributeType, "ShortName");
            }
            try
            {
                attribute2.GetDescription();
            }
            catch (InvalidOperationException exception3)
            {
                throw new AttributeBuilderException(exception3, attributeType, "Description");
            }
            try
            {
                attribute2.GetPrompt();
            }
            catch (InvalidOperationException exception4)
            {
                throw new AttributeBuilderException(exception4, attributeType, "Prompt");
            }
            if (attribute2.GetAutoGenerateField().HasValue)
            {
                declaration.NamedParameters.Add("AutoGenerateField", attribute2.AutoGenerateField);
            }
            if (attribute2.GetAutoGenerateFilter().HasValue)
            {
                declaration.NamedParameters.Add("AutoGenerateFilter", attribute2.AutoGenerateFilter);
            }
            if (!string.IsNullOrEmpty(attribute2.Description))
            {
                declaration.NamedParameters.Add("Description", attribute2.Description);
            }
            if (!string.IsNullOrEmpty(attribute2.GroupName))
            {
                declaration.NamedParameters.Add("GroupName", attribute2.GroupName);
            }
            if (!string.IsNullOrEmpty(attribute2.Name))
            {
                declaration.NamedParameters.Add("Name", attribute2.Name);
            }
            if (attribute2.GetOrder().HasValue)
            {
                declaration.NamedParameters.Add("Order", attribute2.Order);
            }
            if (!string.IsNullOrEmpty(attribute2.Prompt))
            {
                declaration.NamedParameters.Add("Prompt", attribute2.Prompt);
            }
            if (attribute2.ResourceType != null)
            {
                declaration.NamedParameters.Add("ResourceType", attribute2.ResourceType);
            }
            if (!string.IsNullOrEmpty(attribute2.ShortName))
            {
                declaration.NamedParameters.Add("ShortName", attribute2.ShortName);
            }
            return declaration;
        }
    }
}

